package cn.iocoder.yudao.module.system.service.strategy;

import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class OrderFactory {

    private final Map<String, OrderStrategy> strategyMap;

    /**
     * 构造方法自动注入所有实现了 Strategy 接口的 Bean
     * Spring 会自动将所有 Bean 按类型存入 Map
     */
    public OrderFactory(Map<String, OrderStrategy> strategyMap) {
        this.strategyMap = strategyMap;
    }

    /**
     * 根据类型获取对应的策略
     * @param type 策略类型
     * @return 策略实例
     */
    public OrderStrategy getStrategy(String type) {
        OrderStrategy strategy = strategyMap.get(type);
        if (strategy == null) {
            throw new IllegalArgumentException("No strategy found for type: " + type);
        }
        return strategy;
    }

}
